﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Common
{
    /// <summary>
    /// 进制转换
    /// </summary>
    public class ToolsScale
    {
        /// <summary>
        /// 16进制转10进制
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static int change16To10(string value)
        {
            return Convert.ToInt32(value, 16);
        }

        /// <summary>
        /// 8进制转10进制
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static int change8To10(string value)
        {
            return Convert.ToInt32(value, 8);
        }

        /// <summary>
        /// 10进制转16进制
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string change10To16(int value)
        {
            return Convert.ToString(value, 16);
        }

        /// <summary>
        /// 10进制转16进制
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string change10To16(int value, int length)
        {
            if (value < 0)
            {
                return Convert.ToString(Int16.Parse(value.ToString()), 16).PadLeft(length, '0');
            }
            else
            {
                return Convert.ToString(value, 16).PadLeft(length, '0');
            }
        }

        /// <summary>
        /// 10进制转8进制
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string change10To8(int value)
        {
            return Convert.ToString(value, 8);
        }

        /// <summary>
        /// 10进制转2进制
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string change10To2(int value)
        {
            return Convert.ToString(value, 2);
        }

    }
}

